package org.hot100_3;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class leetcode74 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[] array = new int[m * n];
        int index = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                array[index] = matrix[i][j];
                index++;
            }
        }

        int left = 0;
        int right = array.length - 1;

        while (left <= right) {
            int mid = (left + right) >>> 1;
            if (array[mid] < target) {
                left = mid + 1;
            } else if (target < array[mid]) {
                right = mid - 1;
            } else {
                return true;
            }
        }

        return false;
    }
}
